//
//  huiyuanshiwusuoViewController.m
//  PASystem
//
//  Created by michael on 16/7/21.
//  Copyright © 2016年 czd. All rights reserved.
//
#import "huiyuanshiwuTableViewCell.h"
#import "MaoCuhui2TableViewController.h"
#import "huiyuanshiwusuoViewController.h"
#import "guoneiwaiViewController.h"
#import "peixunuvguanliTableViewController.h"
#import "InternationController.h"
@interface huiyuanshiwusuoViewController ()

@end

@implementation huiyuanshiwusuoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
        self.view.backgroundColor = [UIColor whiteColor];

    self.title = @"会员事务部";

// _array = @[@"会员管理",@"系统管理",@"国内外交流与联络管理",@"培训与会议管理"];
//  _array1 = @[@"省本级企业会员",@"支会企业会员",@"企业基础库"];
//   _array2 = @[@"贸促会",@"国际商会"];
//    _array3 = @[@"国内活动",@"国外活动",@"国内接待",@"国外接待"];
//     _array4 = @[@"企业培训",@"经贸洽谈",@"高访考察",@"会议交流",@"企业考察"];
//     _array5 = @[_array1,_array2,_array3,_array4];
//    
//     self.tableView.bounces = NO;
      [self requestdata];

}
- (void)requestdata{

       _array = [NSMutableArray array];
        _array5 = [NSMutableArray array];

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];

 NSString *json =[NSString stringWithFormat: @"{'action':'getJurisdiction','service':'UserService', 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,name:会员事务部}'}",userId,pwdId,userHumber];
     NSArray * array = @[@{@"arg0":json}];

     [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
     NSArray *array0 = JSON[@"reason"];
     
     
     for (NSDictionary *dic in array0) {
    NSArray *array1 = dic[@"value"];
    NSDictionary *dic1 = [array1 firstObject];
    NSString *string = dic1[@"meut"];
    [_array addObject:string];
    NSArray *array2 =dic1[@"value"];
        NSMutableArray *array = [NSMutableArray array];

for (NSDictionary *dic in array2) {
    NSString *string = dic [@"name"];
    [array addObject:string];
    
    
}
[_array5 addObject:array];
}
     
     
[self initview];

       NSLog(@"%@",JSON);
         

    } failure:^(NSError *error) {
        
    }];


}
- (void)initview{
_tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
//     self.tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate =self;
//     self.tableView.bounces = NO;

[self.view addSubview:_tableView];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _array.count;
}
#pragma mark UITableView dataScource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 static NSString *CellIdentifier = @"Cell1111";

    huiyuanshiwuTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[huiyuanshiwuTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
   NSArray *array = _array5 [indexPath.section];
cell.array = array;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
float itemHeight = (KScreenHeight-46-64) /5;

   NSArray *array = _array5 [indexPath.section];
   if (array.count>4) {
    return itemHeight*3/2;
}else{
return itemHeight*4/5;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   float itemHeight = (KScreenHeight-46-64) /5;

 UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, itemHeight*1/4)];
    view1.backgroundColor = [UIColor whiteColor];
    UIView *viewcolor = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, view1.height)];
    viewcolor.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"图标3"]];
    [view1 addSubview:viewcolor];
     UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(viewcolor.right, viewcolor.top+5, 200, view1.height-5)];
    label.text = _array[section];
    [view1 addSubview:label];

    return view1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
   float itemHeight = (KScreenHeight-46-64) /5;
        return itemHeight*1/4;
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
                return 1;
 }



@end
